/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import java.util.Properties;
import javax.mail.Address;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 *
 * @author MoroComputer
 */
public class GerenciadorDeEmail {

    
    //senha 1077330023
    public static void enviaEmail(String assunto, String conteudo, String emailDestinatario) {
        try {
            // email.setFrom("siskeplergerenciador2014@gmail.com", "Siskepler"); // remetente
            Properties props = new Properties();
            /**
             * Parâmetros de conexão com servidor Gmail
             */
            props.put("mail.smtp.host", "smtp.gmail.com");
            props.put("mail.smtp.socketFactory.port", "465");
            props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
            props.put("mail.smtp.auth", "true");
            props.put("mail.smtp.port", "465");

            Session session = Session.getDefaultInstance(props,
                    new javax.mail.Authenticator() {
                        protected PasswordAuthentication getPasswordAuthentication() {
                            return new PasswordAuthentication("siskeplergerenciador2014@gmail.com", "1077330023");
                        }
                    });

            /**
             * Ativa Debug para sessão
             */
            session.setDebug(true);

            try {

                Message message = new MimeMessage(session);
                message.setFrom(new InternetAddress("siskeplergerenciador2014@gmail.com")); //Remetente

                Address[] toUser = InternetAddress //Destinatário(s)
                        .parse(emailDestinatario);

                message.setRecipients(Message.RecipientType.TO, toUser);
                message.setSubject(assunto);//Assunto
                message.setText(conteudo);
                /**
                 * Método para enviar a mensagem criada
                 */
                Transport.send(message);

            } catch (MessagingException e) {
                throw new RuntimeException(e);
            }

        } catch (Exception erro) {

        }
    }
}
